//
//  LeetCodeTests.swift
//  LeetCodeTests
//
//  Created by zhulongiMac02 on 2018/7/20.
//  Copyright © 2018年 zhulongiMac02. All rights reserved.
//

import XCTest
@testable import LeetCode

class LeetCodeTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    // MARK: - 队列
    // 测试Offer队列50
    func testOfferList50() throws {
        let problem = ProblemOffer50()
        problem.solution()
        XCTAssertEqual(problem.firstUniqChar("abaccdeff"), "b")
        XCTAssertEqual(problem.firstUniqChar(""), " ")
        XCTAssertEqual(problem.firstUniqChar("leetcode"), "l")
    }
    
    // 测试Offer队列59
    func testOfferList59() throws {
        let problem = ProblemOffer59()
        let array = problem.maxSlidingWindow([1,3,-1,-3,5,3,6,7], 3)
        XCTAssertEqual(array, [3,3,5,5,6,7])
    }
    
    // 测试Offer队列59_2
    func testOfferList59_2() throws {
        let problem = MaxQueue()
        problem.push_back(1)
        problem.push_back(2)
        
        XCTAssertEqual(problem.max_value(), 2)
        XCTAssertEqual(problem.pop_front(), 1)
        XCTAssertEqual(problem.max_value(), 2)
        
        
        let problem1 = MaxQueue()
        XCTAssertEqual(problem1.pop_front(), -1)
        XCTAssertEqual(problem1.max_value(), -1)
    }
    
    // 测试Offer队列20
    func testOfferList20() throws {
        let problem = ProblemOffer30()
        problem.push(-2)
        problem.push(0)
        problem.push(-3)
        
        XCTAssertEqual(problem.min(), -3)
        problem.pop()
        XCTAssertEqual(problem.top(), 0)
        XCTAssertEqual(problem.min(), -2)
    }

    
    // MARK: - 递归
    func testOfferList16() throws {
        let problem = ProblemOffer16()
        XCTAssertEqual(problem.myPow(2.0, 10),  1024.0)
        XCTAssertEqual(problem.myPow(2.1, 3),   9.261)
        XCTAssertEqual(problem.myPow(2.0, -2),  0.25)
    }
    func testOfferList62() throws {
        let problem = ProblemOffer62()
        XCTAssertEqual(problem.lastRemaining(5, 3), 3)
        XCTAssertEqual(problem.lastRemaining(10, 17), 2)
    }
    
    
    // MARK: - 字符串
    func testOfferString57_2() throws {
        let problem = ProblemOffer57_2()
        let list = problem.findContinuousSequence(15)
        print(list)
        print(problem.findContinuousSequence(16))
        print(problem.findContinuousSequence(150))
        print(problem.findContinuousSequence(320))
        print(problem.findContinuousSequence(3))
        print(problem.findContinuousSequence(2222))
    }
    
    func testOfferString48() throws {
        let problem = ProblemOffer48()
        XCTAssertEqual(problem.lengthOfLongestSubstring("abcabcbb"), 3)
        XCTAssertEqual(problem.lengthOfLongestSubstring("bbbbb"), 1)
        XCTAssertEqual(problem.lengthOfLongestSubstring("pwwkew"), 3)
        XCTAssertEqual(problem.lengthOfLongestSubstring("au"), 2)
        XCTAssertEqual(problem.lengthOfLongestSubstring("auu"), 2)
        XCTAssertEqual(problem.lengthOfLongestSubstring("aua"), 2)
        XCTAssertEqual(problem.lengthOfLongestSubstring("auc"), 3)
    }
    
    func testOfferString58_1() throws {
        let problem = ProblemOffer58_1()
        XCTAssertEqual(problem.reverseWords("the sky is blue"), "blue is sky the")
        XCTAssertEqual(problem.reverseWords("  hello world!  "), "world! hello")
        XCTAssertEqual(problem.reverseWords("a good   example"), "example good a")
        XCTAssertEqual(problem.reverseWords(""), "")
        XCTAssertEqual(problem.reverseWords(" "), "")
        XCTAssertEqual(problem.reverseWords("    "), "")
    }
    
    func testOfferString20() throws {
        let problem = ProblemOffer20()
        XCTAssertEqual(problem.isNumber("0"), true)
        XCTAssertEqual(problem.isNumber("    .1  "), true)
        XCTAssertEqual(problem.isNumber("+100"), true)
        XCTAssertEqual(problem.isNumber("5e2"), true)
        XCTAssertEqual(problem.isNumber("-123"), true)
        XCTAssertEqual(problem.isNumber("3.1416"), true)
        XCTAssertEqual(problem.isNumber("-1E-16"), true)
        XCTAssertEqual(problem.isNumber("0123"), true)
        
        XCTAssertEqual(problem.isNumber("e"), false)
        XCTAssertEqual(problem.isNumber("."), false)
        XCTAssertEqual(problem.isNumber("12e"), false)
        XCTAssertEqual(problem.isNumber("1a3.14"), false)
        XCTAssertEqual(problem.isNumber("1.2.3"), false)
        XCTAssertEqual(problem.isNumber("+-5"), false)
        XCTAssertEqual(problem.isNumber("12e+5.4"), false)

    }
    
    func testOfferString38() throws {
        let problem = ProblemOffer38()
        print(problem.permutation("abc"))
    }
    
    // MARK: - 位运算
    func testOffer65() throws {
        let problem = ProblemOffer65()
        XCTAssertEqual(problem.add(1, 1), 2)
        XCTAssertEqual(problem.add(4, 10), 14)
        XCTAssertEqual(problem.add(-1, 2), 1)
    }
    
    // MARK: - 数组
    func testOffer17() throws {
        let problem = ProblemOffer17()
        print(problem.printNumbersLarge(3))
    }
    func testOffer51() throws {
        let problem = ProblemOffer51()
//        XCTAssertEqual(problem.reversePairs([7,5,6,4]), 5)
//        XCTAssertEqual(problem.reversePairs([1,7,5,6,20,4,3]), 11)
//        XCTAssertEqual(problem.reversePairs([1,3,2,3,1]), 4)        // 4
//        XCTAssertEqual(problem.reversePairs([1,2,1,2,1]), 3)        // 3
        
        
//        XCTAssertEqual(problem.reversePairs2([7,5,6,4]), 5)
//        XCTAssertEqual(problem.reversePairs2([1,7,5,6,20,4,3]), 11)
        XCTAssertEqual(problem.reversePairs2([1,3,2,3,1]), 4)
//        XCTAssertEqual(problem.reversePairs2([1,2,1,2,1]), 3)
    }
    
    
}
